package com.data.modules.ai.constant;

import cn.hutool.core.io.resource.ResourceUtil;
import lombok.Getter;

import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;

@SuppressWarnings("ALL")
@Getter
public enum AiRuleH5PropertyEnum {

    reset(1,"bootstrap.reset","conf/def.properties"),
    def(1,"bootstrap.def","conf/def.properties"),
    elm(2,"elm","conf/def.properties"),
    mt(3,"mt","conf/def.properties"),
    rl(4,"rl","conf/def.properties")
    ;

    private Integer code;

    private String desc;

    private String remark;

    AiRuleH5PropertyEnum(Integer code, String desc, String remark) {
        this.code = code;
        this.desc = desc;
        this.remark = remark;
    }

    public static String getHeaderByCode(String code){
        AiRuleH5PropertyEnum[] enums = values();
        for (AiRuleH5PropertyEnum anEnum : enums) {
            if (Objects.equals(anEnum.name(),code)){
                InputStream stream = ResourceUtil.getStream(anEnum.getRemark());
                Properties properties = new Properties();
                try {
                    properties.load(stream);
                } catch (IOException e) {
                    //TODO 啥都不做
                    return "";
                }
                String property = properties.getProperty(anEnum.getDesc());
                return Objects.isNull(property)?"":property;
            }
        }
        return "";
    }

    public static void composeParam(String param,Map<String, Object> map){
        String[] split = param.split("=");
        map.put(split[0],split[1]);
    }
}
